package net.xdclass.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author Administrator
 * @description
 * @since 2023-07-02 22:18
 */
@Component
@Slf4j
public class MybatisPlusHandler implements MetaObjectHandler {
    /**
     * 自动填充 数据库字段 （插入）
     * @param metaObject 元对象
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        LocalDateTime now = LocalDateTime.now();
        this.strictInsertFill(metaObject, "ctDate", LocalDateTime.class, now);
        this.strictInsertFill(metaObject, "ltDate", LocalDateTime.class, now);
    }

    /**
     * 自动填充 数据库字段 （修改）
     * @param metaObject 元对象
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        LocalDateTime now = LocalDateTime.now();
        this.strictUpdateFill(metaObject, "ltDate", LocalDateTime.class, now);
    }
}
